﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using DTO;
using System.Data;

namespace DAO
{
    public class DAO_report
    {
        public static List<DTO_SinhVien> SelectSinhVien_report(string malop, string makh)
        {
            List<DTO_SinhVien> listSinhVien = new List<DTO_SinhVien>();
            try
            {
                string s = "Prc_ReportSV";
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = ketnoi.Cmb();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = s;
                cmd.Parameters.Add("@MaLop", SqlDbType.NVarChar).Value = malop;
                cmd.Parameters.Add("@MaKH", SqlDbType.NVarChar).Value = makh;
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = cmd;
                DataTable dt = new DataTable();
                da.Fill(dt);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DTO_SinhVien SV = new DTO_SinhVien();
                    SV.MaSV = dt.Rows[i]["MaSV"].ToString();
                    SV.TenSV = dt.Rows[i]["TenSV"].ToString();
                    if ((bool)dt.Rows[i]["GioiTinh"] == false)
                        SV.GioiTinh = false;
                    else
                        SV.GioiTinh = true;
                    SV.NgaySinh = DateTime.Parse(dt.Rows[i]["NgaySinh"].ToString());
                    SV.MaLop = dt.Rows[i]["MaLop"].ToString();
                    SV.DiaChi = dt.Rows[i]["DiaChi"].ToString();
                    SV.Email = dt.Rows[i]["Email"].ToString();
                    SV.SDT = dt.Rows[i]["SDT"].ToString();
                    SV.MaKH = dt.Rows[i]["MaKH"].ToString();
                    listSinhVien.Add(SV);
                }
                ketnoi.Cmb().Close();
                return listSinhVien;
            }
            catch (Exception ex)
            {
                return listSinhVien;
            }
        }
        public static DataTable SelectSinhVien_report__(string malop)
        {
            DataTable dt = new DataTable();
            try
            {
                string s = "Prc_ReportSV";
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = ketnoi.Cmb();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = s;
                cmd.Parameters.Add("@MaLop", SqlDbType.NVarChar).Value = malop;
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = cmd;
                
                da.Fill(dt);
                ketnoi.Cmb().Close();
                return dt;
            }
            catch (Exception ex)
            {
                return dt;
            }
        }
    }
}
